<!DOCTYPE html>
<html lang="zh-CN">





<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/apple-touch-icon.png">
  <link rel="icon" type="image/png" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="description" content="安全行业从业者，主要方向PC逆向附带安卓和Linux逆向，时不时喜欢写点BUG代码">
  <meta name="author" content="Cray">
  <meta name="keywords" content="">
  <title>Powershell基础 ~ 逆向安全博客</title>

  <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/5.12.1/css/all.min.css"  >
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css"  >
<link rel="stylesheet" href="https://cdn.staticfile.org/mdbootstrap/4.13.0/css/mdb.min.css"  >
<link rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/3.0.1/github-markdown.min.css"  >

<link rel="stylesheet" href="//at.alicdn.com/t/font_1067060_qzomjdt8bmp.css">



  <link rel="stylesheet" href="/lib/prettify/tomorrow.min.css"  >

<link rel="stylesheet" href="/css/main.css"  >


  <link rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css"  >


<meta name="generator" content="Hexo 5.2.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">


    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
          <li class="nav-item">
            <a class="nav-link" href="/">首页</a>
          </li>
        
          
          
          
          
          <li class="nav-item">
            <a class="nav-link" href="/archives/">归档</a>
          </li>
        
          
          
          
          
          <li class="nav-item">
            <a class="nav-link" href="/tags/">标签</a>
          </li>
        
          
          
          
          
          <li class="nav-item">
            <a class="nav-link" href="/links/">友链</a>
          </li>
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="view intro-2" id="background" false
      style="background: url('https://cdn.jsdelivr.net/gh/L0yy/tuchuang/Img/20200302103202.png') no-repeat center center;
      background-size: cover;">
    
        <div class="full-bg-img">
        <div class="mask rgba-black-light flex-center">
          <div class="container text-center white-text fadeInUp">
            <span class="h2" id="subtitle">
              
                Powershell基础
              
            </span>

            
              <br>
              

              <p>
                
                  
                  &nbsp;<i class="far fa-chart-bar"></i>
                  <span class="post-count">
                    529 字
                  </span>&nbsp;
                

                
                  
                  &nbsp;<i class="far fa-clock"></i>
                  <span class="post-count">
                      2 分钟
                  </span>&nbsp;
                

                
                  <!-- 不蒜子统计文章PV -->
                  
                  &nbsp;<i class="far fa-eye" aria-hidden="true"></i>&nbsp;
                  <span id="busuanzi_container_page_pv">
                    <span id="busuanzi_value_page_pv"></span> 次
                  </span>&nbsp;
                
              </p>
            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="py-5 z-depth-3" id="board">
        <div class="post-content mx-auto" id="post">
          <div class="markdown-body">
            <h3 id="Powershell基础"><a href="#Powershell基础" class="headerlink" title="Powershell基础"></a>Powershell基础</h3><p>参考微软<a target="_blank" rel="noopener" href="https://docs.microsoft.com/zh-cn/powershell/scripting/how-to-use-docs?view=powershell-7">官方文档</a></p>
<p>几个特性：</p>
<blockquote>
<ol>
<li>.NET Core可跨平台，powershell6可在Mac Linux平台使用，大气</li>
<li>Win10自带组建，功能强大</li>
</ol>
</blockquote>
<h4 id="了解Powershell"><a href="#了解Powershell" class="headerlink" title="了解Powershell"></a>了解Powershell</h4><ol>
<li>输出基于对象<ul>
<li>PowerShell cmdlet 旨在处理对象</li>
<li>在大多数情况下，可以使用标准 PowerShell 对象语法直接访问数据的各部分</li>
</ul>
</li>
<li>命令系列是可扩展的<ul>
<li>可以自己实现函数</li>
<li>支持批处理文件的脚本</li>
</ul>
</li>
<li>PowerShell 处理控制台输入和显示<ul>
<li>在cmdlet 后使用 <strong>-？</strong>可显示关于此命令的帮助</li>
</ul>
</li>
<li>PowerShell 使用某些 C# 语法</li>
</ol>
<h4 id="了解powershell的名称"><a href="#了解powershell的名称" class="headerlink" title="了解powershell的名称"></a>了解powershell的名称</h4><pre><code> 1. Cmdlet 使用谓词-名词的名称来减少命令记忆
 - [PowerShell 批准的谓词]( https://docs.microsoft.com/zh-cn/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands?view=powershell-7 )
 2. Cmdlet 使用标准参数
 - 参数主要通过**-？**获取，还有通用参数如 WhatIf、Confirm、Verbose、Debug、Warn、ErrorAction、ErrorVariable、OutVariable 和 OutBuffer
3. 建议的参数名称
-   加上方便人理解： Force 、Exclude 、Include 、PassThru 、Path 和 CaseSensitive </code></pre>
<h4 id="使用熟悉的命令名称"><a href="#使用熟悉的命令名称" class="headerlink" title="使用熟悉的命令名称"></a>使用熟悉的命令名称</h4><p>​    <strong>1. Powershell 支持常见的Unix 和cmd.exe 的命令</strong></p>
<p>​    </p>
<table>
<thead>
<tr>
<th align="left"></th>
<th align="left"></th>
<th align="left"></th>
<th align="left"></th>
</tr>
</thead>
<tbody><tr>
<td align="left">cat</td>
<td align="left">dir</td>
<td align="left">mount</td>
<td align="left">rm</td>
</tr>
<tr>
<td align="left">cd</td>
<td align="left">echo</td>
<td align="left">move</td>
<td align="left">rmdir</td>
</tr>
<tr>
<td align="left">chdir</td>
<td align="left">erase</td>
<td align="left">popd</td>
<td align="left">sleep</td>
</tr>
<tr>
<td align="left">clear</td>
<td align="left">h</td>
<td align="left">ps</td>
<td align="left">sort</td>
</tr>
<tr>
<td align="left">cls</td>
<td align="left">history</td>
<td align="left">pushd</td>
<td align="left">tee</td>
</tr>
<tr>
<td align="left">copy</td>
<td align="left">kill</td>
<td align="left">pwd</td>
<td align="left">type</td>
</tr>
<tr>
<td align="left">del</td>
<td align="left">lp</td>
<td align="left">r</td>
<td align="left">write</td>
</tr>
<tr>
<td align="left">diff</td>
<td align="left">ls</td>
<td align="left">ren</td>
<td align="left"></td>
</tr>
</tbody></table>
<ol start="2">
<li><p>别名相关操作</p>
<p> <code> Get-Command -Noun Alias</code></p>
</li>
</ol>
<h4 id="获取详细的帮助信息"><a href="#获取详细的帮助信息" class="headerlink" title="获取详细的帮助信息"></a>获取详细的帮助信息</h4><ol>
<li>获取有关 cmdlet 的帮助<ul>
<li>常规帮助 <strong>Get-Help cmdlet</strong>、<strong>man cmdlet</strong> 、<strong>cmdlet   -?</strong> </li>
<li>获取到参数的帮助  <strong>Get-Help cmdlet -Full</strong> </li>
</ul>
</li>
</ol>
<h4 id="使用变量存储对象"><a href="#使用变量存储对象" class="headerlink" title="使用变量存储对象"></a>使用变量存储对象</h4><ol>
<li>使用**$**表示变量</li>
<li>Get-Member $env:获取变量的信息<ul>
<li>可以创建设置键值对，例：<code>$env:LIB_PATH=&#39;/usr/local/lib&#39;</code></li>
</ul>
</li>
</ol>
<h4 id="了解-PowerShell-管道"><a href="#了解-PowerShell-管道" class="headerlink" title="了解 PowerShell 管道"></a>了解 PowerShell 管道</h4><p>​    主要是方法和属性的使用，下面举个例子</p>
<p>​    <code>Get-Location</code> 获取一个pathInfo</p>
<p>​    <code>Get-Location | Get-Member</code>获取这个类的方法和属性</p>
<p>​    想要使用必须先实例化，传给一个变量</p>
<p>​    <code> $myLocal = Get-Location</code>实例化，这个<code>$myLocal</code>拥有<code>Get-Location</code>的全部方法和属性</p>
<p>​    比如<code>$myloc.Drive.Used </code>获取所在驱动内存使用大小，通过<code>Get-Member</code>获取详情</p>
<h4 id="术语表"><a href="#术语表" class="headerlink" title="术语表"></a>术语表</h4><p>powershell的常用术语</p>
<p>建议中英对照看，翻译的有些不易理解</p>
<p><a target="_blank" rel="noopener" href="https://docs.microsoft.com/zh-cn/powershell/scripting/learn/windows-powershell-glossary?view=powershell-7">中文</a></p>
<p><a target="_blank" rel="noopener" href="https://docs.microsoft.com/en-us/powershell/scripting/learn/windows-powershell-glossary?view=powershell-77">英文</a></p>

            <hr>
          </div>
          <br>
          <div>
            <p>
            
            
              <span>
                <i class="iconfont icon-tag"></i>
                
                  <a class="hover-with-bg" href="/tags/Shell/">Shell</a>
                
              </span>
            
            </p>
            
              <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://zh.wikipedia.org/wiki/Wikipedia:CC_BY-SA_3.0%E5%8D%8F%E8%AE%AE%E6%96%87%E6%9C%AC" rel="nofollow noopener noopener">CC BY-SA 3.0协议</a> 。转载请注明出处！</p>
            
          </div>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container">
        <div id="toc">
  <p class="h5"><i class="far fa-list-alt"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>
      </div>
    
  </div>
</div>

<!-- custom -->


<!-- Comments -->
<div class="col-lg-7 mx-auto nopadding-md">
  <div class="container comments mx-auto" id="comments">
    
      <br><br>
      
      
  <div class="disqus" style="width:100%">
    <div id="disqus_thread"></div>
    <script>
      var disqus_config = function () {
        this.page.url = 'http://cve.gitee.io/cve/2020/05/17/shellcode基础/';
        this.page.identifier = '/2020/05/17/shellcode基础/';
      };
      var oldLoad = window.onload;
      window.onload = function () {
        var d = document, s = d.createElement('script');
        s.type = 'text/javascript';
        s.src = '//' + 'crayon-1' + '.disqus.com/embed.js';
        s.setAttribute('data-timestamp', +new Date());
        (d.head || d.body).appendChild(s);
      };
    </script>
    <noscript>Please enable JavaScript to view the <a target="_blank" href="https://disqus.com/?ref_noscript" rel="nofollow noopener noopener">comments
        powered by Disqus.</a></noscript>
  </div>


    
  </div>
</div>

    
  </main>

  
    <a class="z-depth-1" id="scroll-top-button" href="#" role="button">
      <i class="fa fa-chevron-up scroll-top-arrow" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  <footer class="mt-5">
  <div class="text-center py-3">
    <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><b>Hexo</b></a>
    <i class="iconfont icon-love"></i>
    <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"> <b>Fluid</b></a>
    <br>

    
  
    <!-- 不蒜子统计PV -->
    
    &nbsp;<span id="busuanzi_container_site_pv"></span>总访问量 
          <span id="busuanzi_value_site_pv"></span> 次&nbsp;
  
  
    <!-- 不蒜子统计UV -->
    
    &nbsp;<span id="busuanzi_container_site_uv"></span>总访客数 
            <span id="busuanzi_value_site_uv"></span> 人&nbsp;
  
  <br>



    


    <!-- cnzz Analytics icon -->
    

  </div>
</footer>

<!-- SCRIPTS -->
<script src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script src="https://cdn.staticfile.org/popper.js/1.16.1/umd/popper.min.js" ></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script src="https://cdn.staticfile.org/mdbootstrap/4.13.0/js/mdb.min.js" ></script>
<script src="/js/main.js" ></script>


  <script src="/js/lazyload.js" ></script>



  
  <script src="https://cdn.staticfile.org/tocbot/4.10.0/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var navHeight = $('#navbar').height();
      var toc = $('#toc');
      var main = $('main');
      var tocT = navHeight + (toc.offset().top - main.offset().top);
      var tocLimMin = main.offset().top - navHeight;
      var tocLimMax = $('#comments').offset().top - navHeight;
      $(window).scroll(function () {
        var scroH = document.body.scrollTop + document.documentElement.scrollTop;
        if (tocLimMin <= scroH && scroH <= tocLimMax) {
          toc.css({
            'display': 'block',
            'position': 'fixed',
            'top': tocT,
          });
        } else if (scroH <= tocLimMin) {
          toc.css({
            'position': '',
            'top': '',
          });
        } else if (scroH > tocLimMax) {
          toc.css('display', 'none');
        }
      });
      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: '.post-content',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        scrollSmooth: true,
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc > p').css('visibility', 'visible');
      }
    });
  </script>







  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>


<!-- Plugins -->



  <script src="https://cdn.staticfile.org/prettify/188.0.0/prettify.min.js" ></script>
  <script>
    $(document).ready(function () {
      $('pre').addClass('prettyprint  linenums');
      prettyPrint();
    })
  </script>





  <script src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      getSearchFile(path);
      this.onclick = null
    }
  </script>



  <script src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <script>
    $("#post img:not(.no-zoom img, img[no-zoom])").each(
      function () {
        var element = document.createElement("a");
        $(element).attr("data-fancybox", "images");
        $(element).attr("href", $(this).attr("src"));
        $(this).wrap(element);
      }
    );
  </script>












</body>
</html>
